package cn.bluemobi.platform.controller.withdrawals;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.common.core.dto.MapDto;
import cn.bluemobi.common.core.dto.PageCondition;
import cn.bluemobi.platform.core.controller.PlatformBaseController;
import cn.bluemobi.platform.core.dto.DatatablePage;
import cn.bluemobi.platform.entity.withdrawals.Withdrawals;
import cn.bluemobi.platform.service.WithdrawalsService;

/**
 * 
 * @author lvxh
 * 
 */
@Controller
@RequestMapping("/admin/withdrawals")
public class WithdrawalsController extends PlatformBaseController {

	@Autowired
	private WithdrawalsService withdrawalsService;

	@RequestMapping("/toWithdrawalsPage")
	public String toWithdrawalsPage(Model model) {
		return "withdrawals/withdrawalsList";
	}

	@RequestMapping("/findWithdrawalss")
	@ResponseBody
	public DatatablePage findwithdrawalss(PageCondition cond) {
		return new DatatablePage(cond,
				withdrawalsService.findWithdrawalss(cond));
	}

	@RequestMapping("/toWithdrawalsDetailPage")
	public String toWithdrawalsDetailPage(
			@RequestParam(value = "withdrawalsId", required = false) String withdrawalsId,
			ModelMap model) {
		if (!StringUtils.isEmpty(withdrawalsId)) {
			Withdrawals withdrawals = withdrawalsService
					.findWithdrawalsDetail(withdrawalsId);
			model.put("withdrawals", withdrawals);
		}
		return "withdrawals/withdrawalsDetail";
	}

	@RequestMapping("/saveWithdrawals")
	@ResponseBody
	public MapDto savewithdrawals(Withdrawals withdrawals) {
		return withdrawalsService.saveOrUpdate(withdrawals, getUser());
	}

	@RequestMapping("/deleteWithdrawals")
	@ResponseBody
	public MapDto deleteById(@RequestParam("withdrawalsId") String withdrawalsId) {
		return withdrawalsService.deleteWithdrawals(withdrawalsId, getUser());
	}

	@RequestMapping("/audit")
	@ResponseBody
	public MapDto audit(@RequestParam("withdrawalsId") String withdrawalsId) {
		return withdrawalsService.audit(withdrawalsId, getUser());
	}

}
